package com.zhuge_new.untils;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.widget.TextView;

import com.tencent.mm.opensdk.modelbiz.SubscribeMiniProgramMsg;
import com.zhuge_new.R;

/**
 * Created by lenovo on 2018-08-30.
 */

public class TimerUtil extends CountDownTimer {

    private TextView mtextview;
    private String msg;
    private String skit;

    public TimerUtil(TextView textView,long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.mtextview=textView;
    }

    public TimerUtil(TextView textView,long millisInFuture, long countDownInterval,String msg,String skit) {
        super(millisInFuture, countDownInterval);
        this.mtextview=textView;
        this.msg=msg;
        this.skit=skit;
    }


    @Override
    public void onTick(long millisUntilFinished) {
        mtextview.setClickable(false);
        if (skit.isEmpty()){
            skit="秒后重发";
        }
        mtextview.setText(millisUntilFinished/1000 + skit);
        if (msg.isEmpty()){
            mtextview.setBackgroundResource(R.drawable.bg_identify_code_press);
        }else {
            mtextview.setBackgroundResource(R.drawable.rec_bg_trans_ova);
        }

        SpannableString spannableString = new SpannableString(mtextview.getText().toString());  //获取按钮上的文字
        ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);

    }

    @Override
    public void onFinish() {
        Log.e(msg,"打印数据");
        Log.e(skit,"打印数据");
        if (msg.isEmpty()){
            msg="重新获取验证码";
            mtextview.setClickable(true);//重新获得点击
            mtextview.setBackgroundResource(R.drawable.bg_identify_code_normal);
        }else {
            mtextview.setClickable(true);//重新获得点击
            mtextview.setBackgroundResource(R.drawable.rec_bg_trans_ova);
        }
        mtextview.setText(msg);

    }
}
